//
//  SelectPriceRangeViewController.m
//  iShop
//
//  Created by svp on 25/12/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SelectPriceRangeViewController.h"
#import "TitleTextfieldCell.h"
#import "ResourceLoader.h"

@implementation SelectPriceRangeViewController

@synthesize priceSegment = _priceSegment;
@synthesize tableView = _tableView;
@synthesize insetView = _insetView;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	[self.view bringSubviewToFront:_insetView];
	self.title = @"Price Range";
	//_priceSegment.selectedSegmentIndex = 0;
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	switch (_priceSegment.selectedSegmentIndex) {
		case UISegmentedControlNoSegment:
			return 0;
			break;
		case 0:
			return 1;
			break;
		case 1:
			return 2;
			break;
		case 2:
			return 1;
			break;
		default:
			break;
	}
	return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	TitleTextfieldCell* cell = (TitleTextfieldCell*)[tableView dequeueReusableCellWithIdentifier:@"TitleTextfieldCell"];
	if (!cell) {
		ResourceLoader *rc = [[[ResourceLoader alloc] initWithNibNamed:@"TitleTextfieldCell"] autorelease];
		cell = (TitleTextfieldCell*)rc.resource;
		cell.delegate = self;
	}
	switch (_priceSegment.selectedSegmentIndex) {
		case 0:
			cell.titleLabel.text = @"Maximum Price";
			break;
		case 1:
			cell.titleLabel.text = indexPath.row == 0? @"From": @"To";
			break;
		case 2:
			cell.titleLabel.text = @"Minimum Price";
			break;
		default:
			break;
	}
	return cell;
}

-(IBAction) segmentChange:(id) sender
{
	NSLog(@"segmentChange");
	[_tableView reloadData];
}

@end
